package com.woniu.microassetserver.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.microassetserver.mapper.VendorManagementMapper;
import com.woniu.microassetserver.service.VendorManagementService;
import com.woniu.microcommonsserver.entity.VendorManagementEntity;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


@Transactional(readOnly = true)
@Service
public class VendorManagementServiceImpl implements VendorManagementService {

    @Resource
    private VendorManagementMapper vendorManagementMapper;


    @Override
    public PageInfo<VendorManagementEntity> findAllByParams(int pageNum, int pageSize, VendorManagementEntity vendorManagementEntity) {
        return PageHelper.startPage(pageNum,pageSize).
                doSelectPageInfo(()->vendorManagementMapper.findAllByParams(vendorManagementEntity));
    }



    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int saveVendorManagement(VendorManagementEntity vendorManagementEntity) {
        return vendorManagementMapper.saveVendorManagement(vendorManagementEntity);
    }

    @Override
    public VendorManagementEntity getOneById(Long id) {
        return vendorManagementMapper.getOneById(id);
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int updateVendorManagement(VendorManagementEntity vendorManagementEntity) {
        return vendorManagementMapper.updateVendorManagement(vendorManagementEntity);
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int deleteVendorManagement(Long id) {
        return vendorManagementMapper.deleteVendorManagement(id);
    }
}